var e = require("../../../../@babel/runtime/helpers/toConsumableArray"), t = require("../../../../@babel/runtime/helpers/typeof"), a = getApp();

Page({
    data: {
        currentBaseTabIndex: "0",
        is_enterprise_content: !1,
        is_enterprise_center_content: !1,
        currentEnterpriseTabIndex: "0",
        is_enterprise_first_content: !1,
        is_enterprise_second_content: !1,
        is_enterprise_third_content: !1,
        currentEnterpriseCenterTabIndex: "0",
        is_enterprise_center_first_content: !1,
        is_enterprise_center_second_content: !1,
        is_enterprise_center_third_content: !1,
        active: "",
        active1: "",
        active2: "",
        active2show: !1,
        enterpriseBaseActiveName: "enterprise",
        enterpriseInfo_1: {},
        enterpriseRatioDatas: [],
        enterpriseSupplier: 0,
        enterpriseActiveName: "enterprise_first",
        enterprise_first_content: [],
        enterprise_second_content: [],
        enterprise_third_content: [],
        enterprise_store_number: 0,
        enterpriseCenterInfo_1: {},
        enterpriseCenterRatioDatas: [],
        enterpriseCenterSupplier: 0,
        enterpriseCenterActiveName: "enterprise_center_first",
        enterprise_center_first_content: [],
        enterprise_center_second_content: [],
        enterprise_center_third_content: [],
        enterprise_level_title: "",
        enterprise_level_li: "",
        erchants_name: "",
        erchants_ratio: "",
        store_number: 0,
        isLoadMore: !0,
        total_page: 0,
        page: 1,
        total_page2: 0,
        page2: 1,
        total_page3: 0,
        page3: 1,
        total_page4: 0,
        page4: 1,
        total_page5: 0,
        page5: 5,
        total_page6: 0,
        page6: 1,
        merchant_center: "",
        merchant_people: "",
        merchant_reward: "",
        merchant_title: ""
    },
    onLoad: function(e) {
        var a = e.selectIndex || 0;
        this.data.currentBaseTabIndex = a, this.setData({
            active: a
        }), 1 != this.data.currentBaseTabIndex || this.data.active2show || this.setData({
            active2show: !0
        });
        try {
            var n = function() {
                for (var e = wx.getStorageSync("yz_basic_info"), t = e.popularize_page.mini.vue_route, a = 0; a < t.length; a++) if ("enterprise_index" == t[a]) return console.log(e.popularize_page.mini.mini_url + "跳转的路径"), 
                wx.showToast({
                    title: "未开启推广权限",
                    duration: 2e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: e.popularize_page.mini.mini_url
                            });
                        }, 1e3);
                    }
                }), {
                    v: void 0
                };
            }();
            if ("object" === t(n)) return n.v;
        } catch (e) {
            console.log(e);
        }
        this.setDataByTabIndex(), this.getEnterpriseInfo_4("", 1), this.initLang();
    },
    onReady: function() {},
    onShow: function() {
        this.getEnterpriseInfo_2(), this.getEnterpriseInfo_1();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    setDataByTabIndex: function() {
        "0" != this.data.currentBaseTabIndex || this.data.is_enterprise_content ? "1" == this.data.currentBaseTabIndex && this.data.is_enterprise_center_content ? this.getEnterpriseCenterData() : "1" != this.data.currentBaseTabIndex || this.data.is_enterprise_center_content || (console.log("走哪里"), 
        this.isEnterpriseCenter()) : (this.data.is_enterprise_content = !0, this.getEnterpriseData());
    },
    enterpriseBaseHandleClick: function(e) {
        this.data.currentBaseTabIndex != e.detail.index && (this.data.currentBaseTabIndex = e.detail.index, 
        1 != this.data.currentBaseTabIndex || this.data.active2show || this.setData({
            active2show: !0
        }), this.setDataByTabIndex());
    },
    isEnterpriseCenter: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.get-center-permission");
        a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                if (1 === a.result) {
                    if (-1 == a.data.status) return e.data.is_enterprise_center_content = !1, void wx.navigateTo({
                        url: "/packageB/member/enterprise/enterprose_center_apply/enterprose_center_apply"
                    });
                    1 == a.data.status && (e.data.is_enterprise_center_content = !0, e.getEnterpriseCenterData());
                } else wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseCenterData: function() {
        this.getEnterpriseCenterInfo_1(), this.getEnterpriseCenterInfo_2(), this.getEnterpriseCenterInfo_3(), 
        this.setEnterpriseCenterDataByTabIndex(), this.getStoreNumber();
    },
    getStoreNumber: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.store.list.getStoreCount");
        a._getNetWork({
            url: t,
            data: {},
            success: function(t) {
                var a = t.data;
                1 === a.result ? e.setData({
                    store_number: a.data.store_count
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    gotoStoreList: function(e) {
        var t = e.currentTarget.dataset.num;
        wx.navigateTo({
            url: "/packageB/member/enterprise/enterprise_store/enterprise_store?type=" + t
        });
    },
    getEnterpriseCenterInfo_1: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.merchant-center");
        a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                1 === a.result ? e.setData({
                    enterpriseCenterInfo_1: a.data
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseCenterInfo_2: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.merchant.get-merchant-statistic");
        t += "&merchant_type=1", a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                if (1 === a.result) {
                    e.setData({
                        enterpriseCenterRatioDatas: []
                    });
                    var n = [], r = {};
                    r.money = a.data.today, r.data = "今日", r.name = "data", n.push(r);
                    var s = {};
                    s.money = a.data.yesterday, s.data = "昨日", s.name = "data", n.push(s);
                    var i = {};
                    i.money = a.data.this_week, i.data = "本周", i.name = "data", n.push(i);
                    var o = {};
                    o.money = a.data.this_month, o.data = "本月累计" + e.data.merchant_reward, o.name = "mounth", 
                    n.push(o), e.setData({
                        enterpriseCenterRatioDatas: n
                    });
                } else wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseCenterInfo_3: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.merchant-center-supplier");
        a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                1 === a.result ? e.setData({
                    enterpriseCenterSupplier: a.data.total
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseCenterInfo_4: function(t, n) {
        var r = this, s = this, i = a.getNetAddresss("plugin.merchant.frontend.merchant.get-merchant-list");
        i += "&merchant_type=1&status=" + t + "&page=" + n, a._getNetWork({
            url: i,
            success: function(t) {
                var a = t.data;
                if (r.setData({
                    isLoadMore: !0
                }), 1 === a.result) if (1 == n) "0" == r.data.currentEnterpriseCenterTabIndex ? (r.setData({
                    enterprise_center_first_content: a.data.data,
                    total_page4: a.data.last_page
                }), s.data.total_page4 || r.setData({
                    total_page4: 0
                })) : "1" == r.data.currentEnterpriseCenterTabIndex ? (r.setData({
                    enterprise_center_second_content: a.data.data,
                    total_page5: a.data.last_page
                }), s.data.total_page5 || r.setData({
                    total_page5: 0
                })) : "2" == r.data.currentEnterpriseCenterTabIndex && (r.setData({
                    enterprise_center_third_content: a.data.data,
                    total_page6: a.data.last_page
                }), s.data.total_page6 || r.setData({
                    total_page6: 0
                })); else {
                    var i = a.data.data;
                    if ("0" == r.data.currentEnterpriseCenterTabIndex) {
                        var o = [].concat(e(s.data.enterprise_center_first_content), e(i));
                        s.setData({
                            enterprise_center_first_content: o,
                            total_page4: a.data.last_page
                        });
                    } else if ("1" == r.data.currentEnterpriseCenterTabIndex) {
                        var c = [].concat(e(s.data.enterprise_center_second_content), e(i));
                        s.setData({
                            enterprise_center_second_content: c,
                            total_page5: a.data.last_page
                        });
                    } else if ("2" == r.data.currentEnterpriseCenterTabIndex) {
                        var d = [].concat(e(s.data.enterprise_center_third_content), e(i));
                        s.setData({
                            enterprise_center_third_content: d,
                            total_page6: a.data.last_page
                        });
                    }
                } else wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    enterpriseCenterHandleClick: function(e) {
        this.data.currentEnterpriseCenterTabIndex != e.detail.index && (this.data.currentEnterpriseCenterTabIndex = e.detail.index, 
        this.setWatchMore2(e.detail.index), this.setEnterpriseCenterDataByTabIndex());
    },
    setEnterpriseCenterDataByTabIndex: function() {
        "0" != this.data.currentEnterpriseCenterTabIndex || this.data.is_enterprise_center_first_content ? "1" != this.data.currentEnterpriseCenterTabIndex || this.data.is_enterprise_center_second_content ? "2" != this.data.currentEnterpriseCenterTabIndex || this.data.is_enterprise_center_third_content || (this.data.is_enterprise_center_third_content = !0, 
        this.getEnterpriseCenterInfo_4("0", 1)) : (this.data.is_enterprise_center_second_content = !0, 
        this.getEnterpriseCenterInfo_4("1", 1)) : (this.data.is_enterprise_center_first_content = !0, 
        this.getEnterpriseCenterInfo_4("", 1));
    },
    getEnterpriseData: function() {
        this.getEnterpriseInfo_1(), this.getEnterpriseInfo_2(), this.getEnterpriseInfo_3(), 
        this.setEnterpriseDataByTabIndex(), this.getEnterpriseStoreNumber();
    },
    getEnterpriseStoreNumber: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.store.list.getStoreCountByStaff");
        a._getNetWork({
            url: t,
            data: {},
            success: function(t) {
                var a = t.data;
                1 === a.result ? e.setData({
                    enterprise_store_number: a.data.store_count
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseInfo_1: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.merchant-staff");
        a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                1 === a.result ? e.setData({
                    enterpriseInfo_1: a.data,
                    erchants_name: a.data.realname,
                    erchants_ratio: a.data.bonus_ratio,
                    enterprise_level_title: a.data.has_one_staff_level ? a.data.has_one_staff_level.level_name : "",
                    enterprise_level_li: a.data.has_one_staff_level ? a.data.has_one_staff_level.bonus_ratio : ""
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseInfo_2: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.merchant.get-merchant-statistic");
        t += "&merchant_type=0", a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                if (1 === a.result) {
                    e.setData({
                        enterpriseRatioDatas: []
                    });
                    var n = [], r = {};
                    r.money = a.data.today, r.data = "今日", r.name = "data", n.push(r);
                    var s = {};
                    s.money = a.data.yesterday, s.data = "昨日", s.name = "data", n.push(s);
                    var i = {};
                    i.money = a.data.this_week, i.data = "本周", i.name = "data", n.push(i);
                    var o = {};
                    o.money = a.data.this_month, o.data = "本月累计" + e.data.merchant_reward, o.name = "mounth", 
                    n.push(o), e.setData({
                        enterpriseRatioDatas: n
                    });
                } else wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseInfo_3: function() {
        var e = this, t = a.getNetAddresss("plugin.merchant.frontend.merchant-staff-supplier");
        a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                1 === a.result ? e.setData({
                    enterpriseSupplier: a.data.total
                }) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getEnterpriseInfo_4: function(t, n) {
        var r = this, s = this, i = a.getNetAddresss("plugin.merchant.frontend.merchant.get-merchant-list");
        i += "&merchant_type=0&status=" + t + "&page=" + n, a._getNetWork({
            url: i,
            success: function(t) {
                var a = t.data;
                if (r.setData({
                    isLoadMore: !0
                }), 1 === a.result) if (1 == n) "0" == r.data.currentEnterpriseTabIndex ? (r.setData({
                    enterprise_first_content: a.data.data,
                    total_page: a.data.last_page
                }), s.data.total_page || r.setData({
                    total_page: 0
                })) : "1" == r.data.currentEnterpriseTabIndex ? (r.setData({
                    enterprise_second_content: a.data.data,
                    total_page2: a.data.last_page
                }), s.data.total_page2 || r.setData({
                    total_page2: 0
                })) : "2" == r.data.currentEnterpriseTabIndex && (r.setData({
                    enterprise_third_content: a.data.data,
                    total_page3: a.data.last_page
                }), s.data.total_page3 || r.setData({
                    total_page3: 0
                })); else {
                    var i = a.data.data;
                    if ("0" == r.data.currentEnterpriseTabIndex) {
                        var o = [].concat(e(s.data.enterprise_first_content), e(i));
                        s.setData({
                            enterprise_first_content: o,
                            total_page: a.data.last_page
                        });
                    } else if ("1" == r.data.currentEnterpriseTabIndex) {
                        var c = [].concat(e(s.data.enterprise_second_content), e(i));
                        s.setData({
                            enterprise_second_content: c,
                            total_page2: a.data.last_page
                        });
                    } else if ("2" == r.data.currentEnterpriseTabIndex) {
                        var d = [].concat(e(s.data.enterprise_third_content), e(i));
                        s.setData({
                            enterprise_third_content: d,
                            total_page3: a.data.last_page
                        });
                    }
                } else wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    setWatchMore: function(e) {
        switch (e) {
          case 0:
            if (this.data.page >= this.data.total_page) return;
            this.setData({
                isLoadMore: !0
            });
            break;

          case 1:
            if (this.data.page2 >= this.data.total_page2) return;
            this.setData({
                isLoadMore: !0
            });
            break;

          case 2:
            if (this.data.page3 >= this.data.total_page3) return;
            this.setData({
                isLoadMore: !0
            });
            break;

          default:
            console.log("error:: 找不到匹配项");
        }
    },
    setWatchMore2: function(e) {
        switch (e) {
          case 0:
            if (this.data.page4 >= this.data.total_page4) return;
            this.setData({
                isLoadMore: !0
            });
            break;

          case 1:
            if (this.data.page5 >= this.data.total_page5) return;
            this.setData({
                isLoadMore: !0
            });
            break;

          case 2:
            if (this.data.page6 >= this.data.total_page6) return;
            this.setData({
                isLoadMore: !0
            });
            break;

          default:
            console.log("error:: 找不到匹配项");
        }
    },
    enterpriseHandleClick: function(e) {
        this.data.currentEnterpriseTabIndex != e.detail.index && (this.data.currentEnterpriseTabIndex = e.detail.index, 
        this.setWatchMore(e.detail.index), this.setEnterpriseDataByTabIndex());
    },
    setEnterpriseDataByTabIndex: function() {
        "0" != this.data.currentEnterpriseTabIndex || this.data.is_enterprise_first_content ? "1" != this.data.currentEnterpriseTabIndex || this.data.is_enterprise_second_content ? "2" != this.data.currentEnterpriseTabIndex || this.data.is_enterprise_third_content || (this.data.is_enterprise_third_content = !0, 
        this.getEnterpriseInfo_4("0", 1)) : (this.data.is_enterprise_second_content = !0, 
        this.getEnterpriseInfo_4("1", 1)) : (this.data.is_enterprise_first_content = !0, 
        this.getEnterpriseInfo_4("", 1));
    },
    goTosupper: function(e) {
        var t = e.currentTarget.dataset.num;
        wx.navigateTo({
            url: "/packageB/member/enterprise/enterprise_center_supplier/enterprise_center_supplier?type=" + t
        });
    },
    getMoreData: function() {
        if (this.setData({
            isLoadMore: !1
        }), "0" == this.data.currentBaseTabIndex) switch (this.data.currentEnterpriseTabIndex) {
          case "0":
            if (this.data.page >= this.data.total_page) return;
            var e = this.data.page;
            e += 1, this.setData({
                page: e
            }), this.getEnterpriseInfo_4("", this.data.page);
            break;

          case "1":
            if (this.data.page2 >= this.data.total_page2) return;
            var t = this.data.page2;
            t += 1, this.setData({
                page2: t
            }), this.getEnterpriseInfo_4("1", this.data.page2);
            break;

          case "2":
            if (this.data.page3 >= this.data.total_page3) return;
            var a = this.data.page3;
            a += 1, this.setData({
                page3: a
            }), this.getEnterpriseInfo_4("0", this.data.page3);
            break;

          default:
            console.log("error:: 找不到匹配项");
        } else if ("1" == this.data.currentBaseTabIndex) switch (this.data.currentEnterpriseCenterTabIndex) {
          case "0":
            if (this.data.page4 >= this.data.total_page4) return;
            var n = this.data.page4;
            n += 1, this.setData({
                page4: n
            }), this.getEnterpriseCenterInfo_4("", this.data.page4);
            break;

          case "1":
            if (this.data.page5 >= this.data.total_page5) return;
            var r = this.data.page5;
            r += 1, this.setData({
                page5: r
            }), this.getEnterpriseCenterInfo_4("1", this.data.page5);
            break;

          case "2":
            if (this.data.page6 >= this.data.total_page6) return;
            var s = this.data.page6;
            s += 1, this.setData({
                page6: s
            }), this.getEnterpriseCenterInfo_4("0", this.data.page6);
            break;

          default:
            console.log("error:: 找不到匹配项");
        }
    },
    initLang: function() {
        var e = wx.getStorageSync("mailLanguage");
        if (e) {
            var t = JSON.parse(e);
            this.setData({
                merchant_center: t.merchant.merchant_center || "招商中心",
                merchant_people: t.merchant.merchant_people || "招商员",
                merchant_reward: t.merchant.merchant_reward || "分红",
                merchant_title: t.merchant.title || "招商"
            }), wx.setNavigationBarTitle({
                title: this.data.merchant_title
            });
        }
    }
});